<?php
/**
 * bll series
 * @package app-drama_lib_bll
 */
load_lib('/bll/base');
load_lib('/dao/seriesdao');
/**
 * bll series
 * @author pandajingjing
 * @package app-drama_lib_bll
 */
class bll_series extends bll_base{

    /**
	 * 搜索节目
	 * @param array $p_arrParam
	 * @param int $p_intPage
	 * @return array
	 */
    function searchSeries($p_arrParam,$p_intPage){
        $p_arrParam['SORT']='SERID desc';
        $arrSeriesList=dao_seriesdao::getSeriesList($p_arrParam,$p_intPage);
        $arrData=&$arrSeriesList['DATA'];
        $arrPage=&$arrSeriesList['PAGE'];
        $intCnt=count($arrData);
        if($intCnt>0){
            $arrTypeList=$this->getTypeList();
            $arrRatioList=$this->getRatioList();
            $arrClassList=$this->getClassList();
            for($i=0;$i<$intCnt;++$i){
                $arrData[$i]['INDEX']=($arrPage['CURRENTPAGE']['INDEX']-1)*$arrPage['PAGESIZE']+$i+1;
                foreach($arrTypeList as $arrType){
                    if($arrData[$i]['TYPEID']==$arrType['TYPEID']){
                        $arrData[$i]['TYPESTR']=$arrType['CNAME'];
                    }
                }
                foreach($arrRatioList as $arrRatio){
                    if($arrData[$i]['RATIOID']==$arrRatio['RATIOID']){
                        $arrData[$i]['RATIOSTR']=$arrRatio['CNAME'];
                    }
                }
                foreach($arrClassList as $arrClass){
                    if($arrData[$i]['CLASSID']==$arrClass['CLASSID']){
                        $arrData[$i]['CLASSSTR']=$arrClass['CNAME'];
                    }
                }
            }
        }
        return $arrSeriesList;
    }

    /**
	 * 获得节目详细信息
	 * @param int $p_intSerID
	 * @return array/null
	 */
    function getSeriesDetail($p_intSerID){
        $arrData=dao_seriesdao::getSeriesDetail($p_intSerID);
        if(null===$arrData){
            return $arrData;
        }
        $arrClassList=$this->getClassList();
        $arrTypeList=$this->getTypeList();
        $arrRatioList=$this->getRatioList();
        foreach($arrClassList as $arrClass){
            if($arrData['CLASSID']==$arrClass['CLASSID']){
                $arrData['CLASSSTR']=$arrClass['CNAME'];
            }
        }
        foreach($arrTypeList as $arrType){
            if($arrData['TYPEID']==$arrType['TYPEID']){
                $arrData['TYPESTR']=$arrType['CNAME'];
            }
        }
        foreach($arrRatioList as $arrRatio){
            if($arrData['RATIOID']==$arrRatio['RATIOID']){
                $arrData['RATIOSTR']=$arrRatio['CNAME'];
            }
        }
        return $arrData;
    }

    /**
	 * 保存节目
	 * @param int $p_intSeriesID
	 * @param string $p_strCName
	 * @param string $p_strEName
	 * @param int $p_intClassID
	 * @param int $p_intTypeID
	 * @param int $p_intRatioID
	 * @param int $p_intSaw
	 * @return int
	 */
    function saveSeries($p_intSeriesID,$p_strCName,$p_strEName,$p_intClassID,$p_intTypeID,$p_intRatioID,$p_intSaw){
        load_lib('/util/string');
        if(!util_string::chkDataType($p_intSeriesID,'int')){
            return array( 
                    'Sys_Error_NoSeriesID' 
            );
        }
        $arrErrInfo=$this->chkSeriesInfo($p_strCName,$p_strEName,$p_intClassID,$p_intTypeID,$p_intRatioID);
        if(!empty($arrErrInfo)){
            return $arrErrInfo;
        }
        if(null===$p_intSaw){
            $p_intSaw=0;
        }
        $arrParam=array( 
                'SERID'=>$p_intSeriesID,
                'CNAME'=>$p_strCName,
                'ENAME'=>$p_strEName,
                'CLASSID'=>$p_intClassID,
                'TYPEID'=>$p_intTypeID,
                'RATIOID'=>$p_intRatioID,
                'SAW'=>$p_intSaw 
        );
        return dao_seriesdao::saveSeries($arrParam);
    }

    /**
	 * 检查节目基本信息
	 * @param string $p_strCName
	 * @param string $p_strEName
	 * @param int $p_intClassID
	 * @param int $p_intTypeID
	 * @param int $p_intRatioID
	 * @return array
	 */
    function chkSeriesInfo($p_strCName,$p_strEName,$p_intClassID,$p_intTypeID,$p_intRatioID){
        load_lib('/util/string');
        $arrErrInfo=array();
        if(true!==util_string::chkStrLength($p_strCName,1,50)){
            $arrErrInfo[]='Err_Logic_CName_LengthErr';
        }
        if(true!==util_string::chkStrLength($p_strEName,0,255)){
            $arrErrInfo[]='Err_Logic_EName_LengthErr';
        }
        load_lib('/util/method');
        $p_intClassID=util_method::filterData($this->getClassList(),'CLASSID',$p_intClassID,0);
        $p_intTypeID=util_method::filterData($this->getTypeList(),'TYPEID',$p_intTypeID,0);
        $p_intRatioID=util_method::filterData($this->getRatioList(),'RATIOID',$p_intRatioID,0);
        if(0==$p_intClassID){
            $arrErrInfo[]='Err_Logic_ClassID_NoValue';
        }
        if(0==$p_intTypeID){
            $arrErrInfo[]='Err_Logic_TypeID_NoValue';
        }
        if(0==$p_intRatioID){
            $arrErrInfo[]='Err_Logic_RatioID_NoValue';
        }
        return $arrErrInfo;
    }

    /**
	 * 添加节目
	 * @param string $p_strCName
	 * @param string $p_strEName
	 * @param int $p_intClassID
	 * @param int $p_intTypeID
	 * @param int $p_intRatioID
	 * @return int/false
	 */
    function addSeries($p_strCName,$p_strEName,$p_intClassID,$p_intTypeID,$p_intRatioID){
        $arrErrInfo=$this->chkSeriesInfo($p_strCName,$p_strEName,$p_intClassID,$p_intTypeID,$p_intRatioID);
        if(!empty($arrErrInfo)){
            return $arrErrInfo;
        }
        $arrParam=array( 
                'CNAME'=>$p_strCName,
                'ENAME'=>$p_strEName,
                'CLASSID'=>$p_intClassID,
                'TYPEID'=>$p_intTypeID,
                'RATIOID'=>$p_intRatioID 
        );
        return dao_seriesdao::addSeries($arrParam);
    }

    /**
	 * 获取节目种类列表
	 * @return array
	 */
    function getClassList(){
        return dao_seriesdao::getClassList(array( 
                'SORT'=>'DORDER desc' 
        ));
    }

    /**
	 * 获取节目类型列表
	 * @return array
	 */
    function getTypeList(){
        return dao_seriesdao::getTypeList(array( 
                'SORT'=>'DORDER desc' 
        ));
    }
}